package com.gengao.springbootcase.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.zip.Inflater;

//    获取连接点的信息
@Component
@Aspect
@Slf4j
public class MyAspect8 {

    @Pointcut("execution(* com.gengao.springbootcase.service.DeptService.*(..))")
    public void pt(){}
    @Before("pt()")
    public void before(JoinPoint joinPoint){

    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
//        获取目标对象类名
        String className = joinPoint.getTarget().getClass().getName();
        log.info(className);
//         获取目标对象方法名
        String methodName = joinPoint.getSignature().getName();
        log.info(methodName);
//          获取目标方法运行时传入的参数
        Object[] args = joinPoint.getArgs();
        log.info("目标方法运行时传入的参数,{}", Arrays.toString(args));

//        放行目标方法以及获取返回值
        Object result=joinPoint.proceed();
        return result;
    }

}
